clear
clear all

set more off

cd "/Users/julioramos/Desktop/trabajo_papers/jpipe_final/replication_files"

use "jpipe_database.dta"

//summary statistics
*outreg2 using summarystats.xls, replace sum(log) label dec(3)


**Table 1

xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

**Table 2

xtreg gasto_trabajo i.cohort i.cohort#i.year pop_conapo margvic concurrent  fordirinv i.year priv_exp acad_exp educontin agegover i.party  escuelas  did, fe vce(cluster st)

xtreg gasto_per_total i.cohort i.cohort#i.year pop_conapo margvic concurrent  perc_homi i.year priv_exp acad_exp educontin agegover i.party  escuelas  did, fe vce(cluster st)

***Table 3

xtivreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

xtivreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

**Table 4

xtreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   did, fe vce(cluster st) 

xtreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover  did, fe vce(cluster st) 

**Figures 2 to 5

gen imagen=0
replace imagen=1 if propdiporiginal>=6

bysort imagen year: egen trend_ninos=mean(perdienewborn)
bysort imagen year: egen trend_gasto=mean(gasto_per_total)
bysort imagen year: egen trend_labor=mean(formallabor)
bysort imagen year: egen trend_trabajo=mean(gasto_trabajo)

label var trend_trabajo "Labor Spending"
label var trend_gasto "Health Spending"
label var trend_labor "Formal Jobs"
label var trend_ninos "Infant Mortality Rate"

gr tw (line trend_trabajo year if imagen==0 & cohort==0, lcolor(red)) (line trend_trabajo year if imagen==1 & cohort==0)

gr tw (line trend_gasto year if imagen==0 & cohort==0, lcolor(red)) (line trend_gasto year if imagen==1 & cohort==0)

gr tw (line trend_ninos year if imagen==0 & cohort==0, lcolor(red)) (line trend_ninos year if imagen==1 & cohort==0)

gr tw (line trend_labor year if imagen==0 & cohort==0, lcolor(red)) (line trend_labor year if imagen==1 & cohort==0)


//Figures

//Event studies

bysort st cohort (year): egen id_0=min(year)

replace id_0=. if cohort==0

bysort st: egen entry_gov=max(id_0)

**********************************
gen ysa=year-entry_gov

tab ysa, gen(ysa_)

gen cero=0

label var ysa_1 "-11" 
label var ysa_2 "-10" 
label var ysa_3 "-9" 
label var ysa_4 "-8" 
label var ysa_5 "-7" 
label var ysa_6 "-6" 
label var ysa_7 "-5" 
label var ysa_8 "-4" 
label var ysa_9 "-3" 
label var ysa_10 "-2" 
label var ysa_11 "-1" 
label var cero "-1"

xtreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   ysa_1-ysa_10 cero ysa_12-ysa_31, fe vce(cluster st)
coefplot, keep( ysa_6 || ysa_7 || ysa_8 || ysa_9 || ysa_10 || cero ) yline(0) vertical omitted xtitle(# Years First Governor Treated by the 1977 Reform) ytitle(Estimate)
graph export "a4.png", as(png) replace

xtreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   ysa_1-ysa_10 cero ysa_12-ysa_31, fe vce(cluster st)
coefplot, keep( ysa_6 || ysa_7 || ysa_8 || ysa_9 || ysa_10 || cero ) yline(0) vertical omitted xtitle(# Years First Governor Treated by the 1977 Reform) ytitle(Estimate)
graph export "a3.png", as(png) replace

xtreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   ysa_1-ysa_10 cero ysa_12-ysa_31, fe vce(cluster st)
coefplot, keep( ysa_6 || ysa_7 || ysa_8 || ysa_9 || ysa_10 || cero ) yline(0) vertical omitted xtitle(# Years First Governor Treated by the 1977 Reform) ytitle(Estimate)
graph export "a2.png", as(png) replace

xtreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   ysa_1-ysa_10 cero ysa_12-ysa_31, fe vce(cluster st)
coefplot, keep( ysa_6 || ysa_7 || ysa_8 || ysa_9 || ysa_10 || cero ) yline(0) vertical omitted xtitle(# Years First Governor Treated by the 1977 Reform) ytitle(Estimate)
graph export "a1.png", as(png) replace

//Tables A3 to A6

xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   perc_homi  (pol_car=did), fe vce(cluster st) 

xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   sub_gov  (pol_car=did), fe vce(cluster st) 


xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   fordirinv  (pol_car=did), fe vce(cluster st) 

xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   sub_gov  (pol_car=did), fe vce(cluster st) 



xtivreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   perc_homi  (pol_car=did), fe vce(cluster st) 

xtivreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   sub_gov  (pol_car=did), fe vce(cluster st) 


xtivreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   fordirinv  (pol_car=did), fe vce(cluster st) 

xtivreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   sub_gov  (pol_car=did), fe vce(cluster st) 




**Tables A7 and A8

bysort state (year): gen gasto_trabajo_lag=gasto_trabajo[_n-1]

bysort state (year): gen gasto_per_total_lag=gasto_per_total[_n-1]


//Lag
xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year gasto_trabajo_lag pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

//Level
xtivreg gasto_trabajo_2 i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

//Lag
xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  gasto_per_total_lag pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

//Level
xtivreg gasto_per_total_2 i.cohort i.year i.cohort#i.year   pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 






//Figures A5 to A8

***Thirty three

clear

set more off

cd "/Users/julioramos/Desktop/trabajo_papers/jpipe_final/replication_files"

use "jpipe_database_robustness.dta"

replace cohort=1 if gover_age_in_1977<33

gen did=cohort*propdiporiginal

label var pol_car "Political Career Path"
label var formallabor "Formal Labor"
label var perdienewborn "Infant Mortality Rate"
label var gasto_per_total "State Health Spending"
label var acreditados "# Job Training Certificates"
label var cohort "Electoral-Reform Affected Governor"
label var pop_conapo "Population"
label var margvic "Margin of Victory"
label var perc_homi "Homicides"
label var priv_exp "Governor Private Experience"
label var acad_exp "Governor Academic Experience"
label var educontin "Governor Education (Years)"
label var party  "Party"
label var escuelas  "# State Schools"
label var did "# Proportional Deputies*Electoral-Reform Affected Governor"
label var fordirinv "Foreign Direct Investment"
label var sub_gov "Substitute Governor"
label var concurrent "Concurrent Elec"
label var gasto_trabajo "State Labor Spending"


xtivreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store unoL

xtivreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store unoN

xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store unoT


xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store unoS



***Thirty two

clear

set more off

cd "/Users/julioramos/Desktop/trabajo_papers/jpipe_final/replication_files"

use "jpipe_database_robustness.dta"

replace cohort=1 if gover_age_in_1977<32

gen did=cohort*propdiporiginal

xtivreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store dosL

xtivreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store dosN

xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store dosT


xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store dosS


***Thirty one

clear

set more off

cd "/Users/julioramos/Desktop/trabajo_papers/jpipe_final/replication_files"

use "jpipe_database_robustness.dta"

replace cohort=1 if gover_age_in_1977<31

gen did=cohort*propdiporiginal

xtivreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store tresL

xtivreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store tresN

xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store tresT


xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store tresS



***Thirty

clear

set more off

cd "/Users/julioramos/Desktop/trabajo_papers/jpipe_final/replication_files"

use "jpipe_database_robustness.dta"

replace cohort=1 if gover_age_in_1977<30

gen did=cohort*propdiporiginal

xtivreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store cuatroL

xtivreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store cuatroN

xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store cuatroT


xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store cuatroS


***Twenty nine

clear

set more off

cd "/Users/julioramos/Desktop/trabajo_papers/jpipe_final/replication_files"

use "jpipe_database_robustness.dta"

replace cohort=1 if gover_age_in_1977<29

gen did=cohort*propdiporiginal

xtivreg formallabor i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store cincoL

xtivreg perdienewborn i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store cincoN

xtivreg gasto_trabajo i.cohort i.year i.cohort#i.year  pop_conapo fordirinv escuelas margvic  i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store cincoT


xtivreg gasto_per_total i.cohort i.year i.cohort#i.year  pop_conapo perc_homi escuelas margvic i.party concurrent priv_exp acad_exp educontin   agegover   (pol_car=did), fe vce(cluster st) 

estimates store cincoS



***Graph
label var pol_car "Estimate"

coefplot unoL dosL tresL cuatroL cincoL, keep(pol_car) xline(82.33793) xtitle(# Formal Jobs)

coefplot unoN dosN tresN cuatroN cincoN, keep(pol_car) xline(0.9591346) xtitle(Infant Mortality Rate)

coefplot unoT dosT tresT cuatroT cincoT, keep(pol_car) xline(0.1945997) xtitle(State Labor Spending)

coefplot unoS dosS tresS cuatroS cincoS, keep(pol_car) xline( -0.1266681) xtitle(State Health Spending)





